#include <bits/stdc++.h>
using namespace std;
const int N = 10010;
int n, a[N];
int main()
{
    cin >> n;
    priority_queue<int, vector<int>, greater<int>> pq;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        pq.push(a[i]);
    }
    
    int sum = 0, ans = 0;
    while(pq.size() > 1){
        int x = pq.top(); 
        pq.pop();
        int y = pq.top();
        pq.pop();
        sum = x + y;
        ans += sum;
        pq.push(sum);
    }
    cout << ans << endl;
    return 0;
}